<?php
/*
Class: GFRequest
PHP Version: PHP 5 is required!!!

Notes: 
Class that will handle the request and prepare the data for the user.
Important issue is UTF-8 encoding with try-catch.


*/

class GFRequest{
	/**
	This function will return the VALUE of the parameter @parameter_name from the request by decoding with urldecode()
	*/
	function getParam($parameter_name){
		global $_REQUEST;
		$result = urldecode($_REQUEST["$parameter_name"]);
		return $result;
	}
	
	/**
	This function will try to create a SimpleXMLElement from the value of the given $parameter_name.
	If a problem occurs hte function will return false
	*/
	function getParamXML($parameter_name){
		try
		{
			$XMLString = GFRequest::getParam($parameter_name);
			if($XMLString==""){
				$result = false;
			}else{
				if (!GFRequest::is_utf8($XMLString)){
					// $XMLString = utf8_encode($XMLString); not needed karim
					//echo "Call utf8_encode!";
				}
				$result = new SimpleXMLElement($XMLString);
			}
		}catch (Exception $e)
		{
			echo '<xmlexception>'.$e->getMessage().'</xmlexception>';
			echo $XMLString;
			$result = false;
		}
		return $result;
	}
	
	/**
	This function checks if a string is valid UTF-8 string
	*/
	function is_utf8($string)
	{
	    return (utf8_encode(utf8_decode($string)) == $string);
	}
}

?>
